package com.telrob.antlr;

import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTree;

import com.telrob.antlr.role.XnLexer;
import com.telrob.antlr.role.XnParser;

public class XnCompile {
	public static void compileCode(String name) {
		try {
			CharStream stream=CharStreams.fromFileName(name);
			XnLexer lex=new XnLexer(stream);
			CommonTokenStream tokens=new CommonTokenStream(lex);
			XnParser parse=new XnParser(tokens);
			ParseTree tree =parse.prog();
			XnVisitor base=new XnVisitor(stream);
			name=name.substring(0,name.length()-2)+".xn";
			base.setOutFile(name);
			base.visit(tree);
			System.err.println("编译完成 "+name);
		}catch(Exception e) {
			e.printStackTrace();
		}
	}
}
